const request = require('request');
const { sys } = require('../config');
const eachLimit = require('async/eachLimit');
const fs = require('fs');
const commonUtil = require('../utils/common_util');

// 户型、方案逻辑测试

const designid = '35f68b35-50d4-44f4-9a66-30cef3b385bd';

const openProject = (headers) => {
  fs.readFile('./src/res/project.txt', 'utf-8', (err, data) => {
    if (err) {
    } else {
      const designidList = data.split(',');
      eachLimit(designidList, 10, (designid, callback) => {
        designid = designid.trim();
        request({
          uri: `${sys.testUrl}project/open?d=${designid}`,  // 构建请求
          headers
        }, (error, response, body) => {
          // commonUtil.compareResult(body, '',"openProject");
          // const data = JSON.parse(body).data;
          if (error) setImmediate(callback);
          fs.writeFile(`E://project/${designid}.json`, body, { flag: 'a' }, (err) => {
            if (err) {
              setImmediate(callback);
            } else {
              setImmediate(callback);
            }
          });
        });
      });
    }
  });
};


exports.testAll = (headers) => {
  // 测试打开方案
  openProject(headers);
};

